<?php
class Offer extends CI_Model
{
	public $tbl_name = 'offers';

	public $col_id = 'id';
	public $col_url = 'url';
	public $col_image = 'image';
	public $col_name = 'name';
	public $col_des = 'des';
	public $col_payout = 'payout';
	public $col_categories = 'categories';
	public $col_countryId = 'countryId';
	public $col_networkId = 'networkId';
	

	public function __contruct()
	{
		parent::__construct();	
	}


	public function getOffersByIP($networkId)
	{
		$this->db->where($this->col_networkId, $networkId);
		// $this->db->where($this->col_countryId, $this->session->userdata('countryId'));
		$query = $this->db->get($this->tbl_name);
		return $query->result();
	}

	public function getOffers($networkId)
	{
		$this->db->where($this->col_networkId, $networkId);
		$query = $this->db->get($this->tbl_name);
		return $query->result();
	}

	public function add($networkId)
	{		

		$data = array(
			$this->col_url			=> $this->input->post('url'),
			$this->col_image  		=> $this->input->post('image'),
			$this->col_name  		=> $this->input->post('name'),
			$this->col_des			=> $this->input->post('des'),
			$this->col_payout  		=> $this->input->post('payout'),
			$this->col_categories   => $this->input->post('categories'),
			$this->col_countryId  	=> $this->input->post('countryId'),
			$this->col_networkId 	=> $networkId
		);

		return $this->db->insert($this->tbl_name, $data);
	}

	public function remove($networkId, $id){

		$this->db->where($this->col_networkId, $networkId);
		$this->db->where($this->col_id, $id);
		return $this->db->delete($this->tbl_name);
	}
}
?>